package control;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import persistence.Funcionario_ProjetoDao;
import entity.Funcionario;
import entity.Projeto;

@WebServlet("/ControleProjeto")
public class ControleProjeto extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String cmd = request.getParameter("cmd");
		if(cmd.equalsIgnoreCase("relacionar")){
			relacionar(request, response);
		}
	}
	
	protected void relacionar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			Funcionario f = new Funcionario();
			Projeto p = new Projeto();
			
			try {
				f.setIdFuncionario(new Integer(request.getParameter("funcionario")));
				p.setIdProjeto(new Integer(request.getParameter("projeto")));
				
				new Funcionario_ProjetoDao().create(f, p);
				
				request.setAttribute("msg", "Funcionario Alocado!!");
				
				
			} catch (Exception ex) {
				request.setAttribute("msg", "Erro: " + ex.getMessage());
				ex.printStackTrace();
			}finally{
				request.getRequestDispatcher("alocar.jsp").forward(request, response);
			}
		
		
	}

}
